using System.Collections.Generic;
using System.Linq;
using Crawler.Domain;

namespace Crawler.DomainServices.Download
{
	public interface IDependencyDownloaderProvider
	{
		IDependencyDownloader GetFor(TorrentSource source);
	}

	class DependencyDownloaderProvider : IDependencyDownloaderProvider
	{
		private readonly IEnumerable<IDependencyDownloader> _downloaders;

		public DependencyDownloaderProvider(IEnumerable<IDependencyDownloader> downloaders)
		{
			_downloaders = downloaders;
		}

		public IDependencyDownloader GetFor(TorrentSource source)
		{
			return _downloaders.SingleOrDefault(x => x.ForSource == source);
		}
	}
}